using System;
using System.Windows;
using System.Windows.Controls;

namespace SmartBoard.Core.Command
{
    public static class WPFCommandUIModifier
    {
        public static readonly Func<UIElement,bool, object> EnableDisableUIElement = (control, value)=> control.IsEnabled = value;
        public static readonly Func<bool, UIElement, object> ShowHideUIElement = (value, control) => control.Visibility = value ? Visibility.Visible : Visibility.Collapsed;

        public static readonly Func<MenuItem, bool, object> EnableDisableMenuItem = (control, value) => control.IsEnabled = value;
        public static readonly Func<bool, MenuItem, object> ShowHideMenuItem = (value, control) => control.Visibility = value ? Visibility.Visible : Visibility.Collapsed;
    }

    public static class WPFCommandInitializer
    {
        public static readonly Func<MenuItem, ICommandDescriptor, object> InitializeMenuItem = (m, cd) =>
                                                                                                   {
                                                                                                       if (cd != null)
                                                                                                       {
                                                                                                           m.Click += (s, e) => cd.AssociatedCommand.Execute(null);
                                                                                                           m.Header = cd.Content;
                                                                                                           m.Tag = cd.CommandId;
                                                                                                       }
                                                                                                       else
                                                                                                       {
                                                                                                           throw new ArgumentNullException("cd", "No Descriptor found");
                                                                                                       }
                                                                                                       return null;
                                                                                                   };
    }
}